package com.flac.flacservice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.flac.base.exception.Assert;
import com.flac.base.result.ResponseEnum;
import com.flac.base.util.MD5;
import com.flac.base.util.RandomUtils;
import com.flac.flacservice.mapper.UserAdminMapper;
import com.flac.flacservice.mapper.UserInfoMapper;
import com.flac.flacservice.mapper.UserStatusMapper;
import com.flac.flacservice.pojo.entity.UserAdmin;
import com.flac.flacservice.pojo.entity.UserInfo;
import com.flac.flacservice.pojo.page.PageBean;
import com.flac.flacservice.pojo.query.UserAdminQuery;
import com.flac.flacservice.pojo.query.UserInfoQuery;
import com.flac.flacservice.pojo.vo.UserAdminDTO;
import com.flac.flacservice.pojo.vo.UserAdminVO;
import com.flac.flacservice.pojo.vo.UserInfoDTO;
import com.flac.flacservice.pojo.vo.UserInfoVO;
import com.flac.flacservice.service.UserAdminService;
import com.flac.flacservice.service.UserInfoService;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author DaYouZi
 * @since 2023-03-06
 */
@Service
@Slf4j
public class UserAdminServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserAdminService {

    @Autowired
    private UserAdminMapper userAdminMapper;

    @Override
    public UserAdminVO getInfoById(Integer id) {
        return userAdminMapper.getInfoById(id);
    }

    @Override
    public Boolean foreverRemove(Integer id) {
        return userAdminMapper.foreverRemove(id);
    }

    @Override
    public Boolean updateInfoById(UserAdminDTO userAdminDTO) {
        return userAdminMapper.updateInfoById(userAdminDTO);
    }

    @Override
    public Boolean insertUserInfo(UserAdminDTO userAdminDTO) {
        String userName = userAdminDTO.getUserName();
        UserAdmin userAdmin = userAdminMapper.getInfoByUserName(userName);

        //判断用户是否存在
        Assert.isNull(userAdmin, ResponseEnum.LOGIN_USER_EXISTS);

        return userAdminMapper.insertUserInfo(userAdminDTO);
    }

    @Override
    public PageBean<UserAdminVO> listPage(Integer page, Integer limit, UserAdminQuery userAdminQuery) {
        PageHelper.startPage(page, limit);
        List<UserAdminVO> list = userAdminMapper.listPage(userAdminQuery);
        return new PageBean<>(list);
    }
}
